package com.zr.plant.mapper;

import com.zr.plant.model.LegalPersonVo;
import com.zr.plant.model.PlantSelectVo;
import com.zr.plant.model.PlantVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by lenovo on 2019/12/25.
 */
@Mapper
public interface PlantMapper {
    @Select("select l.*,l.legalPersonId id from legalperson l where userId = #{userid}")
    List<LegalPersonVo> queryLegalPersonById(Integer userid);

    int queryCount(PlantSelectVo plantSelectVo);

    List<PlantVo> queryData(PlantSelectVo plantSelectVo);

    @Select("select count (legalPersonId) from legalperson where legalPersonCode = #{legalPersonCode}")
    int queryLegalPersonByCode(String legalpersoncode);

    @Select("select * from plant where legalPersonCode = #{legalPersonCode}")
    PlantVo queryPlantByCode(@NotBlank(message = "工厂编码不能为空！") String legalPlantCode) ;

    @Insert("insert into plant(legalPlantCode,legalPlantDec,legalpersoncode,enabled,createTime,createName,updateTime,updateName) "  + "values (#{legalPlantCode},#{legalPlantDec},#{legalpersoncode},#{enabled},#{createTime},#{createName},#{updateTime},#{updateName}) ")
    void insertPlant(PlantVo plantVo);

    @Update("update plant set legalPlantDec=#{legalPlantDec},enabled=#{enabled} where legalPlantCode=#{legalPlantCode}")
    void updatePlant(PlantVo plantVo1);

    @Select("select * from plant  where id = #{id}")
    PlantVo queryPlantById(@NotNull(message = "id不能为空！") Integer id);

    @Update("update plant set enabled=#{enabled} where id=#{id}")
    void updateStatusPlant(PlantVo plantVo1);

}
